package com.yhb.controller;

import com.yhb.service.ChannelFlowService;
import com.yhb.service.MPosService;
import com.yhb.third.leshua.LeShuaCheckBoundForm;
import com.yhb.third.leshua.LeShuaCheckBoundVo;
import lombok.extern.log4j.Log4j;
import lombok.var;
import me.edzh.spring.bootstrap.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;


@Log4j
@RestController
@RequestMapping("/third")
public class ThirdController extends BaseController {

    @Autowired
    private MPosService mPosService;

    @Autowired
    private ChannelFlowService channelFlowService;

    @PostMapping("/pos/checkBound")
    public LeShuaCheckBoundVo checkMPosFee(@RequestBody LeShuaCheckBoundForm form) {
        var u = mPosService.checkLeshuaBoundRelationship(form.getSn(), form.getId_number());
        if (u != null) {
            return LeShuaCheckBoundVo.builder()
                    .status_code(1L)
                    .message("查询成功")
                    .data(LeShuaCheckBoundVo.BoundData.builder()
                            .feeRate(channelFlowService.getPosCommission(u.getVipType()))
                            .quick_fee(BigDecimal.valueOf(0)) // 首180天0元提现
                            .build())
                    .build();
        }

        return LeShuaCheckBoundVo.builder()
                .status_code(-1L)
                .message("查询业务方信息失败，请联系您的业务员")
                .build();
    }
}
